﻿@using AVCare.LMS.Util
@model AVCare.LMS.Web.Models.LoginModel
<div class="loginContainer">
    @if (User.Identity.IsAuthenticated)
    {
        <div class="info">
            <div class="headImg">
                <img src="@Url.Content("~/Content/img/head.png")" alt="" style="height: 63px; width: 63px; margin:4px;" />
            </div>
            <div class="basic">   
                @User.Identity.Name  @Html.ActionLink(LanguageHelper.GetString("message.logout"), "Logout", "User")<br />
                <img src="" style="width:16px;height:16px; vertical-align:middle;" />QuickLine1<img src="" style="width:16px;height:16px; vertical-align:middle;" />QuickLine2<br />
                
            </div>
        </div>
        <div class="RoundedCorner">
            <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4">
            </b></b>
                <ul class="infolist">         
                    <li>系统公告(10)</li>
                    <li>短消息(6)</li>
                    <li>日程安排(8)</li>
                    <li>讨论组(29)</li>
                </ul>
            <b class="rbottom"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b
                class="r1"></b></b>
        </div>
    }
    else
    {                                                                                              
        <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.methods.js")" type="text/javascript"></script>  
        <script type="text/javascript">
            jQuery(function ($) {
                $("#changeImage").click(function () {
                    $("#imgValidate").attr("src", "/Validate/CreateValidateImage/" + parseInt(1000 * Math.random()));
                });

                $("#loginForm").validate({
                    rules: {
                        username: {
                            required: true,
                            stringCheck: true
                        },
                        password: {
                            required: true
                        },
                        validatecode: {
                            required: true,
                            digits: true
                        }
                    },
                    /* 设置错误信息 */
                    messages: {
                        username: {
                            required: "@LanguageHelper.GetString("error.empty.username")",
                            stringCheck: "@LanguageHelper.GetString("error.wrong.username")"
                        },
                        password: {
                            required: "@LanguageHelper.GetString("error.empty.password")"
                        },
                        validatecode: {
                            required: "@LanguageHelper.GetString("error.empty.validatecode")",
                            digits: "@LanguageHelper.GetString("error.wrong.validatecode")"
                        }
                    },

                    /* 设置验证触发事件 */
                    onfocusout: false,
                    onkeyup: false,
                    onclick: false, 
                    focusInvalid: false,
                    showErrors: function (errorMap, errorList) {
                        var container = $("#summary");
                        container.empty();
                        for (var i = 0; i < errorList.length; i++) {
                            var li = $("<li>"+errorList[i].message+"</li>");
                            container.append(li);    
                        }
                    },
                    errorPlacement: function(error, element) { },  
                    submitHandler: function (form) {
                        $.ajax({
                            type: "post",
                            url: $("#loginForm").attr("action"),
                            async: false,
                            cache: false,
                            data: $("#loginForm").serialize(),
                            success: function (data) {
                                if (data == "") {
                                    window.location.reload();
                                    return;
                                }
                                var container = $("#summary");
                                container.empty();
                                for (var i = 0; i < errorList.length; i++) {
                                    var li = $("<li>"+errorList[i].message+"</li>");
                                    container.append(li);    
                                }
                                $("#imgValidate").attr("src", "/Validate/CreateValidateImage/" + parseInt(1000 * Math.random()));
                                $("#password").attr("value", "");
                            }
                        });
                    }
                });
            });
    
        </script>    
        <ul id="summary">
        </ul>
        Html.BeginForm("login", "User", FormMethod.Post, new { id = "loginForm" });                       
        <table>
            <tr>
                <td>
                    @LanguageHelper.GetString("label.name")
                </td>
                <td colspan="2">
                    <input type="text" class="styled" name="username" id="username" maxlength="24" />
                </td>
            </tr>
            <tr>
                <td>
                    @LanguageHelper.GetString("label.password")
                </td>
                <td colspan="2">
                    <input type="password" class="styled" name="password" id="password" maxlength="24" />
                </td>
            </tr>
            <tr>
                <td>
                    @LanguageHelper.GetString("label.validate")
                </td>
                <td>
                    <input type="text" class="styled" name="validatecode" id="validatecode" style="width: 60px"
                        maxlength="4" />
                </td>
                <td>
                    <img src="/Validate/CreateValidateImage" id="imgValidate" alt="" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" class="styled" style="width: 60px;" value="@LanguageHelper.GetString("message.login")" />
                </td>
                <td colspan="2">
                    <a href="javascript:void(0)" id="changeImage">@LanguageHelper.GetString("message.changeimg")</a>
                </td>
            </tr>
        </table>
        Html.EndForm();
    }
</div>
